package models;
import java.text.Format;
import java.text.ParseException;
import java.util.Date;
import javax.persistence.*;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Page;
import play.data.format.Formats;
import play.data.validation.Constraints;
import play.db.ebean.Model;
import controllers.JsonDateFormatter;
import controllers.JsonDatetimeFormatter;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import controllers.Helper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import play.libs.Json;
import models.Driver;
@Entity
@Table(name="driver_evaluation")
public class Driver_evaluation extends Model {
	private static final long serialVersionUID = 1L;
	@Id
	public Integer id; //编号
	@JsonSerialize(using=JsonDateFormatter.class)
	public Date evaluation_date; //考评日期
	@ManyToOne
	public Driver driver; //驾驶员姓名
	
	public Integer responsibility; //签约责任书（20分）
	
	public Integer common_violation; //一般违章（10分）
	
	public Integer bad_violation; //严重违章（20分）
	
	public Integer completion; //例保完成（10分)
	
	public Integer learning; //参加学习（10分)
	
	public Integer execution; //作业执行（20分）
	
	public Integer finish_receipe; //衔接单证（10分)
	
	public Integer total; //总评分
	
	public String comments; //评语
	public static Model.Finder<Integer, Driver_evaluation> find = new Model.Finder<Integer, Driver_evaluation>(Integer.class, Driver_evaluation.class);

	public static Page<Driver_evaluation> page(int page, int pageSize, String sortBy, String order, String [] filterColum, String[] filter) {
		ExpressionList<Driver_evaluation> exp = find.where();
		for(int i= 0; i< filterColum.length; i++) {
			String[] tokens = filter[i].split("\\|", 3);
			if (tokens.length == 0) {
				continue;
			}
			String fieldtype = tokens[0];
			if (tokens.length == 3) { //two values, range search
				if (tokens[1].isEmpty() || tokens[2].isEmpty() ) {
					continue;
				}
				Object obj0 = Helper.stringToObject(fieldtype, tokens[1]);
				Object obj1 = Helper.stringToObject(fieldtype, tokens[2]);
				exp = exp.between(filterColum[i], obj0, obj1);
			} else if (tokens.length == 2) { //one value search
				if (tokens[1].isEmpty()) {
					continue;
				}
				if (fieldtype.equalsIgnoreCase("String")) {
					exp = exp.ilike(filterColum[i], "%" + tokens[1] + "%");
				} else {
					Object obj0 = Helper.stringToObject(fieldtype, tokens[1]);
					exp = exp.eq(filterColum[i], obj0);
				}
			}
		}
		return exp.orderBy(sortBy + " " + order).findPagingList(pageSize).setFetchAhead(false).getPage(page);
	}
	public void setId(Integer d) {
		id= d;
	}
	public Integer getId() {
		return id;
	}
	public void setEvaluation_date(Date d) {
		evaluation_date= d;
	}
	public Date getEvaluation_date() {
		return evaluation_date;
	}
	public void setDriver(Driver d) {
		driver= d;
	}
	public Driver getDriver() {
		return driver;
	}
	public void setResponsibility(Integer d) {
		responsibility= d;
	}
	public Integer getResponsibility() {
		return responsibility;
	}
	public void setCommon_violation(Integer d) {
		common_violation= d;
	}
	public Integer getCommon_violation() {
		return common_violation;
	}
	public void setBad_violation(Integer d) {
		bad_violation= d;
	}
	public Integer getBad_violation() {
		return bad_violation;
	}
	public void setCompletion(Integer d) {
		completion= d;
	}
	public Integer getCompletion() {
		return completion;
	}
	public void setLearning(Integer d) {
		learning= d;
	}
	public Integer getLearning() {
		return learning;
	}
	public void setExecution(Integer d) {
		execution= d;
	}
	public Integer getExecution() {
		return execution;
	}
	public void setFinish_receipe(Integer d) {
		finish_receipe= d;
	}
	public Integer getFinish_receipe() {
		return finish_receipe;
	}
	public void setTotal(Integer d) {
		total= d;
	}
	public Integer getTotal() {
		return total;
	}
	public void setComments(String d) {
		comments= d;
	}
	public String getComments() {
		return comments;
	}
	public static Driver_evaluation findById(Integer d) {
		return find.byId(d);
	}
	public static String getIdJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getId().toString(), v.getId().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByEvaluation_date(Date d) {
		return find.where().eq("evaluation_date", d).findUnique();
	}
	public static String getEvaluation_dateJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getEvaluation_date().toString(), v.getEvaluation_date().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByDriver(Driver d) {
		return find.where().eq("driver", d).findUnique();
	}
	public static String getDriverJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getDriver().toString(), v.getDriver().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByResponsibility(Integer d) {
		return find.where().eq("responsibility", d).findUnique();
	}
	public static String getResponsibilityJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getResponsibility().toString(), v.getResponsibility().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByCommon_violation(Integer d) {
		return find.where().eq("common_violation", d).findUnique();
	}
	public static String getCommon_violationJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getCommon_violation().toString(), v.getCommon_violation().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByBad_violation(Integer d) {
		return find.where().eq("bad_violation", d).findUnique();
	}
	public static String getBad_violationJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getBad_violation().toString(), v.getBad_violation().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByCompletion(Integer d) {
		return find.where().eq("completion", d).findUnique();
	}
	public static String getCompletionJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getCompletion().toString(), v.getCompletion().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByLearning(Integer d) {
		return find.where().eq("learning", d).findUnique();
	}
	public static String getLearningJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getLearning().toString(), v.getLearning().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByExecution(Integer d) {
		return find.where().eq("execution", d).findUnique();
	}
	public static String getExecutionJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getExecution().toString(), v.getExecution().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByFinish_receipe(Integer d) {
		return find.where().eq("finish_receipe", d).findUnique();
	}
	public static String getFinish_receipeJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getFinish_receipe().toString(), v.getFinish_receipe().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByTotal(Integer d) {
		return find.where().eq("total", d).findUnique();
	}
	public static String getTotalJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getTotal().toString(), v.getTotal().toString()); 
		}
		return node.toString();
	}
	public static Driver_evaluation findByComments(String d) {
		return find.where().eq("comments", d).findUnique();
	}
	public static String getCommentsJson() {
		ObjectNode node = Json.newObject();
		node.put("", "");
		for(Driver_evaluation v: find.all()) {
			node.put(v.getComments().toString(), v.getComments().toString()); 
		}
		return node.toString();
	}
}
